1
レッスン7:トランスファー学習 ― 知識の活用
EvoClass-AI002Lecture 7
00:00

第7レッスンへようこそ。ここでは トランスファー学習という技術について紹介します。この手法は、巨大な汎用データセット(例:ImageNet)で事前に学習されたディープラーニングモデルを再利用し、新しい特定のタスク(例:私たちのFoodVisionチャレンジ)に適応させるものです。ラベル付きデータが限られている場合でも、優れた成果を効率的に得るために不可欠です。

1. 事前学習済み重みの力

深層ニューラルネットワークは階層的に特徴を学習します。下位レイヤーは基本的な概念(縁、角、テクスチャ)を学び、上位レイヤーはそれらを組み合わせて複雑な概念(目、車輪、特定の物体)を作り出します。重要な洞察は、初期に学んだ基本的な特徴は ほとんどの視覚領域において普遍的に適用可能 であるということです。

トランスファー学習の要素

  • ソースタスク: 1,400万枚の画像と1,000カテゴリ(例:ImageNet)で学習すること。
  • ターゲットタスク: 非常に小さなデータセット(例:私たちの特定のFoodVisionクラス)に分類するように重みを調整すること。
  • 活用される部分: ネットワークのパラメータの大部分――特徴抽出レイヤー――はそのまま再利用されます。
効率の向上
トランスファー学習は、二つの主要なリソース障壁を大幅に削減します: 計算コスト (数日間もモデル全体を訓練しなくて済む)および データ要件 (数百枚のトレーニング例で高い精度が達成可能であり、数千枚は不要)。
train.py
TERMINALbash — pytorch-env
> Ready. Click "Run" to execute.
>
TENSOR INSPECTOR Live

Run code to inspect active tensors
Question 1
What is the primary advantage of using a model pre-trained on ImageNet for a new vision task?
It requires less labeled data than training from scratch.
It completely eliminates the need for any training data.
It guarantees 100% accuracy immediately.
Question 2
In a Transfer Learning workflow, which part of the neural network is typically frozen?
The final Output Layer (Classifier Head).
The Convolutional Base (Feature Extractor layers).
The entire network is usually unfrozen.
Question 3
When replacing the classifier head in PyTorch, what parameter must you first determine from the frozen base?
The batch size of the target data.
The input feature size (the output dimensions of the last convolutional layer).
The total number of model parameters.
Challenge: Adapting the Classifier Head
Designing a new classifier for FoodVision.
You load a ResNet model pre-trained on ImageNet. Its last feature layer outputs a vector of size 512. Your 'FoodVision' project has 7 distinct food classes.
Step 1
What is the required Input Feature size for the new, trainable Linear Layer?
Solution:
The Input Feature size must match the output of the frozen base layer.
Size: 512.
Step 2
What is the PyTorch code snippet to create this new classification layer (assuming the output is named `new_layer`)?
Solution:
The output size of 512 is the input, and the class count 7 is the output.
Code: new_layer = torch.nn.Linear(512, 7)
Step 3
What is the required Output Feature size for the new Linear Layer?
Solution:
The Output Feature size must match the number of target classes.
Size: 7.